# Definition for a binary tree node.
# class TreeNode:
#     def __init__(self, x):
#         self.val = x
#         self.left = None
#         self.right = None

class TreeNode:
    def __init__(self, x):
        self.val = x
        self.left = None
        self.right = None

# 这个解法基于中序遍历，因为中序遍历后，结果是一个有序列表，所以结果不是有序列表，就不对
# 不好的地方时，需要额外申请一个 list 来存储所有的值
class Solution:
    def isValidBST(self, root: TreeNode) -> bool:
        list = []
        self.__inorderItr(root, list)
        prev = None
        for v in list:
            if prev == None:
                prev = v
            else:
                if prev >= v:
                    return False
                else:
                    prev = v
        return True

    def __inorderItr(self, node: TreeNode, list):
        if node == None:
            return
        self.__inorderItr(node.left, list)
        list.append(node.val)
        self.__inorderItr(node.right, list)
